package com.shqcjd.preinstallmobile.ui.fragment;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.ui.activity.ExpertListActivity;
import com.shqcjd.preinstallmobile.ui.adapter.ExpertTypeAdapter;
import com.shqcjd.preinstallmobile.ui.base.BaseFragment;
import com.shqcjd.preinstallmobile.ui.base.BasePresenter;
import com.shqcjd.preinstallmobile.util.SpacesItemDecoration;
import com.shqcjd.preinstallmobile.util.UIUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 专家
 * Created by sy on 2019/3/14.
 */

public class ExpertFragment extends BaseFragment {
    @BindView(R.id.iv_toolbar_back)
    ImageView ivToolbarBack;
    @BindView(R.id.tv_toolbar_center)
    TextView tvToolbarCenter;
    @BindView(R.id.rl_expert_search)
    RelativeLayout rlExpertSearch;
    @BindView(R.id.rv_expert_type)
    RecyclerView rvExpertType;

    public static ExpertFragment newInstance() {
        return new ExpertFragment();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_expert;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }


    @Override
    public void initView(View rootView) {
        tvToolbarCenter.setText("专家");
        ivToolbarBack.setVisibility(View.GONE);
        List<String> data = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            data.add("");
        }
        ExpertTypeAdapter expertTypeAdapter = new ExpertTypeAdapter(data);
        rvExpertType.setLayoutManager(new LinearLayoutManager(getContext()));
        rvExpertType.addItemDecoration(new SpacesItemDecoration(UIUtils.dip2px(6), 0));
        rvExpertType.setAdapter(expertTypeAdapter);
        expertTypeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                //专家类型 1专家 2专工 3供应商 0全部
                int expertType = -1;
                switch (position) {
                    case 0:
                        expertType = 1;
                        break;
                    case 1:
                        expertType = 2;
                        break;
                    case 2:
                        expertType = 3;
                        break;
                }
                Intent intent = new Intent(getContext(), ExpertListActivity.class);
                intent.putExtra("expertType",expertType);
                startActivity(intent);
            }
        });
    }


    @OnClick(R.id.rl_expert_search)
    public void onViewClicked() {
        Intent intent = new Intent(getContext(), ExpertListActivity.class);
        intent.putExtra("expertType",0);
        startActivity(intent);
    }
}
